package com.niit.radiobutton;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView tv_result;
    Button btn_ok;
    RadioGroup rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv_result = findViewById(R.id.result);
        btn_ok = findViewById(R.id.show);
        rg = findViewById(R.id.radioGroup);

        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int SelectedID = rg.getCheckedRadioButtonId();
                if (SelectedID == R.id.radioBtn1){
                    tv_result.setText("You choose 25!");
                }
                if (SelectedID == R.id.radioBtn2){
                    tv_result.setText("You choose 50!");
                }
                if (SelectedID == R.id.radioBtn3){
                    tv_result.setText("You choose 100!");
                }
            }
        });
    }
}
